[HEADER]
	VERSION		00.00.00.00
	DESCRIPTION Ripple Example
	COPYRIGHT	Imagination Technologies Ltd.
[/HEADER]

[TEXTURES]
	FILE textureReflect	cubemap.pvr		LINEAR-LINEAR-LINEAR
[/TEXTURES]

[VERTEXSHADER]
	NAME VertShader
	[GLSL_CODE]
	attribute highp vec3	inVertex;
	attribute mediump vec3	inNormal;
	
	uniform mediump mat4	WorldViewProj;
	uniform mediump mat3	WorldViewIT;
	uniform mediump float 	Animation;
	uniform mediump int 	GeometryCounter;
	
	varying mediump vec3  	Normal;
	varying mediump vec3  	EyeDir;
	varying highp vec4 		Color;
	
	void main(void)
	{
		
		float ripple = 4.0*cos(0.1*(inVertex.z) + (radians(1.0*Animation*360.0)));
		float ripple2 = 1.0*cos(0.1*(inVertex.x) + (radians(2.0*Animation*360.0)));
		
		vec3 vertex = vec3(0);
		
		if(GeometryCounter == 0)
		{
			vertex = inVertex + vec3(ripple,ripple2,ripple2);
			Color = vec4(1.0,0.5,1.0,1);
		}
		else
		{
			Color = vec4(0.5,0.0,1.0,1);
			vertex = inVertex + vec3(ripple2,ripple,ripple2);
		}
		
		gl_Position = WorldViewProj * vec4(vertex,1.0);
		Normal = normalize(WorldViewIT * inNormal);
		EyeDir = -vec3(gl_Position);
	}
	[/GLSL_CODE]
[/VERTEXSHADER]

[FRAGMENTSHADER]
	NAME FragShader
	[GLSL_CODE]
	uniform samplerCube sCubeMap;
	uniform mediump mat3 ViewIT;
	
	varying mediump vec3 Normal;
	varying mediump vec3 EyeDir;
	varying highp vec4 Color;
	
	void main (void)
	{
		mediump vec3 reflectVec = normalize(ViewIT * reflect(EyeDir, Normal));
		mediump vec3 envColour = vec3(textureCube(sCubeMap, reflectVec));

		gl_FragColor = Color * vec4(envColour, 0.5);
	}
	[/GLSL_CODE]
[/FRAGMENTSHADER]

[EFFECT]
	NAME Effect

	ATTRIBUTE	inVertex			POSITION
	ATTRIBUTE	inNormal			NORMAL

	UNIFORM		WorldViewProj		WORLDVIEWPROJECTION
	UNIFORM		WorldViewIT			WORLDVIEWIT
	UNIFORM		ViewIT				VIEWIT
	UNIFORM		Animation			ANIMATION
	UNIFORM		sCubeMap			TEXTURE0
	UNIFORM		GeometryCounter		GEOMETRYCOUNTER

	TEXTURE 0 textureReflect

	VERTEXSHADER VertShader
	FRAGMENTSHADER FragShader
[/EFFECT]
